<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: PortalSystemPage.php 338 2010-01-30 17:59:23Z steen.rabol@gmail.com $
 * @package Pradoportal.Common
 *
 */

Prado::using('Application.Common.PortalBasePage');

/**
 *
 * @package Pradoportal.Common
 */
class PortalSystemPage extends PortalBasePage
{
	public function onInit($p)
	{
		parent::onInit($p);
	}

	public function onPreInit($param)
	{
		parent::onPreInit($param);
		$this->Theme		= "Portal/" . $this->Application->Parameters['ThemeName'];
		$this->MasterClass	= 'Application.Layouts.Portal.' . $this->Application->Parameters['ThemeName'] . '.PortalSystemLayout';
	}

	public function gotoDefaultPage()
	{
		$this->gotoPage($this->Service->DefaultPage,array("PageMode" => $this->EditMode));
	}

	public function getUserRoles()
	{
		return $this->DataAccess->createCommand("select * from tblroles")->query();
	}

	public function ValidateUserRole($p_role)
	{
		$retval	= $this->Application->Parameters['MinRole'];
		$id		= $this->Page->DataAccess->createCommand("select id from tblroles where id='$p_role'")->queryScalar();

		if($id !==null && $id !== false)
		{
			$retval = $id;
		}

		return $retval;
	}

	// We don't want to edit this page
	public function render($writer)
	{
		$oldmode		= TPropertyValue::ensureInteger($this->EditMode);
		$this->EditMode = TPropertyValue::ensureInteger(0);
		parent::render($writer);
		$this->EditMode = TPropertyValue::ensureInteger($oldmode);
	}

	public function RoleNameFromId($id)
	{
		$retval		= "";
		$rolename	= $this->DataAccess->createCommand("select name from tblroles where id=$id")->queryScalar();

		if($rolename)
		{
			$retval = $rolename;
		}

		return $retval;
	}

	public function RoleIdFromName($name)
	{
		$retval	= "";
		$roleid = $this->DataAccess->createCommand("select id from tblroles where name='$name'")->queryScalar();

		if($roleid)
		{
			$retval = $roleid;
		}

		return $retval;
	}

	public function getRoleDataListOptions()
	{
		$retroles	= array();
		$dbroles	= $this->DataAccess->createCommand("select * from tblroles")->query();

		if($dbroles !== null && count($dbroles) > 0)
		{
			$retroles[] = array("id" => "0", "name" => Prado::localize("Select role"));
			foreach($dbroles as $drole)
			{
				$retroles[] = $drole;
			}
		}

		return $retroles;
	}
}
?>